package com.starsoft.frame.base.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.starsoft.frame.base.bean.UserContext;
import com.starsoft.frame.base.service.AcountService;
import com.starsoft.frame.base.service.FlexsetService;
import com.starsoft.frame.base.service.PreferenceService;
import com.starsoft.frame.base.service.UserService;

@RestController
@RequestMapping("/")
public class IndexController {

	@Autowired
	private PreferenceService ps;
	
	@Autowired
	FlexsetService fs;
	
	@Autowired
	AcountService acountService;
	
	@RequestMapping(value = {"", "index"})
	public ModelAndView login(ModelAndView mv) {
		UserContext context = UserService.getUserContext();
		mv.addObject("THEME", ps.getPreference("THEME", context));
		mv.addAllObjects(fs.getFlexsetValues("PLAT_THEME"));
		mv.addObject("acounts", acountService.getParentAcount(context.getUserId()));
		mv.addObject("acount", context.getAcount());
		mv.setViewName("/base/index/index");
		return mv;
	}

}
